package com.zm.campus.controller;


import com.zm.campus.pojo.ReplaceDo;
import com.zm.campus.pojo.RespBean;
import com.zm.campus.pojo.RespBeanEnum;
import com.zm.campus.pojo.Trade;
import com.zm.campus.query.ReplaceDoQuery;
import com.zm.campus.service.IReplaceDoService;
import com.zm.campus.util.AssertUtil;
import com.zm.campus.vo.AuditListVo;
import com.zm.campus.vo.LoginReturnVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zm
 */
@RestController
@RequestMapping("/replaceDo")
public class ReplaceDoController {

    @Autowired
    private IReplaceDoService replaceDoService;

    //发布代劳信息
    @PostMapping("addReplaceDo")
    public RespBean addReplaceDo(@RequestBody ReplaceDo replaceDo) throws ParseException {
        return replaceDoService.addReplaceDo(replaceDo);
    }

    //获取当前登录用户所在学校的所有的代劳信息列表
    @RequestMapping("getAllReplaceDo")
    public RespBean getAllReplaceDo(@RequestBody ReplaceDoQuery replaceDoQuery){
        return replaceDoService.getAllReplaceDo(replaceDoQuery);
    }

    //获取当前需要审核的代劳的数量
    @PostMapping("getNewAuditNums")
    public RespBean getNewAudit(String userId) {

        return replaceDoService.getNewAudit(userId);
    }

    //管理员获取所有待审核的树洞
    @PostMapping("getAllAudit")
    public RespBean getAllAudit(String  role,String userId){
        return  replaceDoService.getAllAudit(role,userId);
    }

    //管理员通过代劳ids审核代劳信息
    @PostMapping("registerReplaceDoByIds")//待审核的ids数组，是否通过，审核人的用户id
    public RespBean registerReplaceDoByIds(AuditListVo auditListVo, Boolean isAudit, String userId){
        return replaceDoService.registerReplaceDoByIds(auditListVo,isAudit,userId);
    }
    //根据指定代劳id删除代劳信息,还有当前操作的用户是管理员才行
    @PostMapping("deleteReplaceDo")
    public RespBean deleteReplaceDo(Long id,String userId){
        return replaceDoService.deleteReplaceDo(id,userId);
    }
    //用户接单
    @PostMapping("receiveReplaceDo")
    public RespBean receiveReplaceDo(@RequestBody Trade trade){
            return replaceDoService.receiveReplaceDo(trade);
    }
    //根据用户id查询可以重新代劳的信息
    @PostMapping("getRepublishRD")
    public RespBean getRepublishRD(String userId){

        AssertUtil.isTrue(StringUtils.isBlank(userId), RespBeanEnum.UserError);
        return replaceDoService.getRepublishRD(userId);
    }

}
